using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Gestion_Comercial
{
    public partial class Proyectos : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //DSGCTableAdapters.ProyectoTableAdapter
            
        }

        protected void ddlComercial_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlCliente.Items.Clear();
            ListItem _li = new ListItem("[ Todos ]", "-1");
            ddlCliente.Items.Add(_li);
            if (((DropDownList)sender).SelectedIndex > 0)
            {
                ddlCliente.Enabled = true;
                ddlCliente.DataBind();
            }
            else
                if (Roles.IsUserInRole(User.Identity.Name, ConfigurationSettings.AppSettings["GerenteRol"]) != true)
                    ddlCliente.Enabled = false;
        }

        protected void ddlComercial_DataBound(object sender, EventArgs e)
        {
            ((DropDownList)sender).SelectedValue = ((Site1)Master).UsuarioActivo.ID.ToString();
        }

        protected void dsClientes_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            //si es gerente
            if (Roles.IsUserInRole(User.Identity.Name, ConfigurationSettings.AppSettings["GerenteRol"]) == true)
                e.InputParameters["pIDComercial"] = -1; // ((DropDownList)LoginView2.FindControl("ddlComercial")).SelectedValue;
            else
                e.InputParameters["pIDComercial"] = ((Site1)Master).UsuarioActivo.ID;
        }

        protected void dsProyectos_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (Roles.IsUserInRole(User.Identity.Name, ConfigurationSettings.AppSettings["GerenteRol"]) == true)
                e.InputParameters["pIDComercial"] = ((DropDownList)LoginView2.FindControl("ddlComercial")).SelectedValue;
            else
                e.InputParameters["pIDComercial"] = ((Site1)Master).UsuarioActivo.ID.ToString();
        }

        protected void ddlCliente_DataBinding(object sender, EventArgs e)
        {

        }

        protected void btnFiltrar_Click(object sender, EventArgs e)
        {
            gvProyectos.DataBind();
        }
    }
}
